import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2025-04-16
 * Time: 16:13
 */


public class demo6 {
    public static void main(String[] args) {
       BlockingDeque queue = new LinkedBlockingDeque(1000);
       Thread producer = new Thread(() -> {
          int n = 0;
          while(true){
              try {
                  queue.put(n);
                  System.out.println("生产者元素" + n);
                  n++;
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
          }
       });

       Thread consumer = new Thread(() -> {
           while(true){
               try {
                   int n = (int) queue.take();
                   System.out.println("消费者元素" + n);
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
       });

       producer.start();
       consumer.start();
    }
}
